﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FocusOnTerrain;
using Lxzhu.OpenGL;
using Tutorials;
namespace FocusOnTerrain.BruteForce
{
    class Program:GlutEngine
    {
        static void Main(string[] args)
        {
            Program rt = new Program();
            rt.Run();
            
        }
        private HeightMap mHeightMap = FocusOnDB.RandomMap(100, 100);
        public Program()
        {

        }
        public override void OnDisplay()
        {
            Gl.glClear(BufferBit.GL_COLOR_BUFFER_BIT);
            Gl.glClearColor(0, 0, 0, 0);

            for (int x = 0; x < mHeightMap.SizeX-1 ; x++)
            {
                double fx0 = x * 1.0 / mHeightMap.SizeX;
                double fx1 = (x + 1) * 1.0 / mHeightMap.SizeX;
                Gl.glBegin(PrimitiveType.GL_TRIANGLES);                
                for (int y = 0; y < mHeightMap.SizeY-1 ; y++)
                {
                    double fy0 = y * 1.0 / mHeightMap.SizeY;
                    double fy1 = (y + 1) * 1.0 / mHeightMap.SizeY;
                    Gl.glColor(1, 0, 0);
                    Gl.glVertex(fx0, fy0, mHeightMap[x, y]);
                    Gl.glColor(0, 1, 0);
                    Gl.glVertex(fx0, fy1, mHeightMap[x, y + 1]);
                    Gl.glColor(0, 0, 1);
                    Gl.glVertex(fx1, fy1, mHeightMap[x + 1, y + 1]);
                    //
                    Gl.glColor(1, 0, 0);
                    Gl.glVertex(fx0, fy0, mHeightMap[x, y]);
                    Gl.glColor(0, 1, 0);
                    Gl.glVertex(fx1, fy1, mHeightMap[x + 1, y + 1]);
                    Gl.glColor(0, 0, 1);
                    Gl.glVertex(fx1, fy0, mHeightMap[x + 1, y ]);
                }
                Gl.glEnd();
            }
        }
    }
}
